import request from '@/axios'
import {
  DepartmentListResponse,
  DepartmentUserParams,
  DepartmentUserResponse,
  CurdData
} from './types'

export const getDepartmentApi = () => {
  return request.get<DepartmentListResponse>({ url: '/mock/department/list' })
}

export const getUserByIdApi = (params: DepartmentUserParams) => {
  return request.get<DepartmentUserResponse>({ url: '/mock/department/users', params })
}

export const deleteUserByIdApi = (ids: string[] | number[]) => {
  return request.post({ url: '/mock/department/user/delete', data: { ids } })
}

export const saveApi = (data: Partial<CurdData>): Promise<IResponse> => {
  if (data.id) {
    return request.put({ url: '/admin/department', data })
  } else {
    return request.post({ url: '/admin/department', data })
  }
}

export const delListApi = (ids: string): Promise<IResponse> => {
  return request.delete({ url: '/admin/department', data: { ids } })
}

export const getListApi = (params: any) => {
  return request.get({ url: '/admin/department', params })
}

export const getTreeSelectOptionApi = () => {
  return request.get({ url: '/admin/department/treeSelectOption' })
}

export const getDepartmentTableApi = (params: any) => {
  return request.get({ url: '/mock/department/table/list', params })
}
